/**
 * 
 */
package ua.kpi.javatrainee6.model;

import ua.kpi.javatrainee6.model.departments.*;
import ua.kpi.javatrainee6.model.people.*;
import java.util.*;

/**
 * Main class for model testing, contains functions for checking main model entities -
 * University, Group, Professor, Student, Administrator functionality. 
 */
public class UniversityModel {
	
	/** testing University entity functionality */
	private static void testUniverFunctionality(University univer) {
		univer.viewAllSections();
		univer.viewAllSubjects();
		univer.viewAllMembers();
		univer.viewCurriculum();
	}
	
	/**testing Group entity functionality */
	private static void testGroupFunctionality(Group group) {
		group.viewAllSections();
		group.viewAllMembers();
		group.viewAllSubjects();
		System.out.printf("Average score of group = %1.2f\n", group.calculateAverage());
		group.viewCurriculum();
	}
	
	/** testing Administrator entity functionality */
	private static void testAdminFunctionality(UniversityAdministrator admin) {
		admin.viewResponsibilities();
		admin.performAssessment();
		System.out.println("Results of assessment");
		for (Group group : admin.getGroups()) {
			System.out.println("For group " + group.getTitle());
			for (Student student : group.getStudents()) {
				student.viewAllMarks();
			}
		}
		System.out.println("Salary: " + admin.calculateSalary());
	}
	
	/** testing Professor entity functionality */
	private static void testProfessorFunctionality(Professor professor) {
		professor.viewResponsibilities();
		professor.viewAllGroups();
		professor.viewCurriculum();
		System.out.println("Salary: " + professor.calculateSalary());
		professor.evaluateAsBadOrGood();
	}
	
	/** testing Student entity functionality */
	private static void testStudentFunctionality(Student student) {
		student.viewResponsibilities();
		student.viewAllMarks();
		System.out.printf("Average score of student = %1.2f\n", student.calculateAverage());
		student.viewCurriculum();
		System.out.println("Salary: " + student.calculateSalary());
		student.evaluateAsBadOrGood();
	}
	
	/** testing Observer pattern, sending messages to the students after assessment */
	private static void testObserverPattern(UniversityAdministrator admin) {
		Group anyGroup = admin.getGroups().get(0);
		Student firstStudent = anyGroup.getStudents()[0];
		Student secondStudent = anyGroup.getStudents()[1];
		firstStudent.becomeObserver();
		secondStudent.becomeObserver();
		System.out.println("FIRST ASSESSMENT");
		admin.performAssessment();	
		System.out.println("SECOND ASSESSMENT");
		Student thirdStudent = anyGroup.getStudents()[2];
		thirdStudent.becomeObserver();
		admin.performAssessment();
		System.out.println("THIRD ASSESSMENT");
		thirdStudent.stopToBeObserver();
		admin.performAssessment();
	}
	
	/**
	 * Main testing function, program entry point
	 * @param args
	 */
	public static void main(String[] args) {
		University univer = new University("KPI", new Date());
		testUniverFunctionality(univer);
		
		UniversityAdministrator admin = univer.getAdmin();
		testAdminFunctionality(admin);
		
		Professor anyProfessor = admin.getProfessors().get(0);
		testProfessorFunctionality(anyProfessor);
		
		Group anyGroup = admin.getGroups().get(0);
		testGroupFunctionality(anyGroup);
		
		Student anyStudent = anyGroup.getStudent(0);
		testStudentFunctionality(anyStudent);
		
		testObserverPattern(admin);
	}
}
